import json
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
class UtilsDriver:
    _mp_driver = None
    _mis_driver = None
    __quit_mis_driver = True
    @classmethod
    def set_quit_driver(cls,mark):
        cls.__quit_mis_driver = mark
    @classmethod
    def get_mp_driver(cls):
        if cls._mp_driver is None:
            cls._mp_driver = webdriver.Chrome()
            cls._mp_driver.maximize_window()
            cls._mp_driver.get("http://pc-toutiao-python.itheima.net/#/login")
        return cls._mp_driver

    @classmethod
    def quit_mp_driver(cls):
        if cls._mp_driver is not None:
            cls.get_mp_driver().quit()
            cls._mp_driver = None
    @classmethod
    def get_mis_driver(cls):
        if cls._mis_driver is None:
            cls._mis_driver = webdriver.Chrome()
            cls._mis_driver.maximize_window()
            cls._mis_driver.get("http://mis-toutiao-python.itheima.net/#/")
        return cls._mis_driver
    @classmethod
    def quit_mis_driver(cls):
        if cls._mis_driver and cls.__quit_mis_driver:
            cls.get_mis_driver().quit()
            cls._mis_driver = None
def choice_channel(driver, element, channel):
    element.click()
    time.sleep(1)
    xpath = "//*[@class='el-select-dropdown__wrap el-scrollbar__wrap']" \
        "//*[text()='{}']".format(channel)
    driver.find_element(By.XPATH, xpath).click()
def is_exist(driver,text):
    xpath = "//*[contains(text(),'{}')]".format(text)
    try:
        time.sleep(2)
        return driver.find_element(By.XPATH, xpath)
    except Exception as e:
        return False
def get_case_data(filename):
    with open(filename, encoding='utf-8') as f:
        case = json.load(f)
        list_case_data = []
        for case_data in case.values():
            list_case_data.append(tuple(case_data.values()))
        return list_case_data